package com.openfire.client.demo;

import java.io.IOException;
import java.util.concurrent.CyclicBarrier;

import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

import com.openfire.client.demo.job.UserConnectionJob;

/**
 * openfire client
 * 
 */
public class BatchUser_dev1 {
	
	public static void main(String[] args) throws InterruptedException, IOException {

		// 202.104.147.108 开发环境
		//String serviceName = "dev.qxclub.cn";
		String serviceName = "localhost";
		String password = "123456";
		String host = "localhost";
		XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
				.setHost(host)
				.setPort(5222).setServiceName(serviceName).setSecurityMode(SecurityMode.disabled)
				.setDebuggerEnabled(false)
				.setConnectTimeout(Integer.MAX_VALUE)
				.build();
		try {
			int userCount = 100;
			CyclicBarrier barrier = new CyclicBarrier(userCount + 1);
			int count = 0;
			while (count < userCount) {
				String username = "batch_user_" + count;
				try {
					new Thread(new UserConnectionJob(username, password, configuration, barrier)).start();

					Thread.sleep(25);
				} catch (Exception e) {
					e.printStackTrace();
				}
				count++;
				System.out.println(count);
			}
			System.out.println("Done!");
			System.in.read();
			System.out.println("read");
			barrier.await();
			System.out.println("await");
		
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
}
